using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_REWARDData : DatabaseObjectBase
	{
		public HRM_REWARDData()
		{
			Initialize(true);
		}
		public HRM_REWARDData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_REWARD_Insert(String RewardCode, String Foundation, String Reason, String Object, String Form, String Level, String Source, Decimal TotalValue, Int32 Status, DateTime Date, String DecideNumber, DateTime DecideDate, String Person)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_REWARD_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RewardCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Foundation", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Object", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Form", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Level", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Source", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@TotalValue", SqlDbType.Money));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DecideDate", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Prepare();
				SqlString RewardCodeSQL = RewardCode;
				_dbadapter.InsertCommand.Parameters["@RewardCode"].Value = RewardCodeSQL;
				SqlString FoundationSQL = Foundation;
				_dbadapter.InsertCommand.Parameters["@Foundation"].Value = FoundationSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.InsertCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString ObjectSQL = Object;
				_dbadapter.InsertCommand.Parameters["@Object"].Value = ObjectSQL;
				SqlString FormSQL = Form;
				_dbadapter.InsertCommand.Parameters["@Form"].Value = FormSQL;
				SqlString LevelSQL = Level;
				_dbadapter.InsertCommand.Parameters["@Level"].Value = LevelSQL;
				SqlString SourceSQL = Source;
				_dbadapter.InsertCommand.Parameters["@Source"].Value = SourceSQL;
				SqlMoney TotalValueSQL = TotalValue;
				_dbadapter.InsertCommand.Parameters["@TotalValue"].Value = TotalValueSQL;
				SqlInt32 StatusSQL = Status;
				_dbadapter.InsertCommand.Parameters["@Status"].Value = StatusSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date"].Value = DateSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.InsertCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlDateTime DecideDateSQL = SqlDateTime.Null;
				if (DecideDate > DateTime.MinValue)
				{
					try
					{
						DecideDateSQL = DecideDate;
					}
					catch (Exception eDecideDate)
					{
						String DecideDateMessage = eDecideDate.Message;
						DecideDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@DecideDate"].Value = DecideDateSQL;
				SqlString PersonSQL = Person;
				_dbadapter.InsertCommand.Parameters["@Person"].Value = PersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_REWARD_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_REWARD_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_REWARD_Update(String RewardCode, String Foundation, String Reason, String Object, String Form, String Level, String Source, Decimal TotalValue, Int32 Status, DateTime Date, String DecideNumber, DateTime DecideDate, String Person)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_REWARD_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RewardCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Foundation", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Object", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Form", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Level", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Source", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TotalValue", SqlDbType.Money));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Prepare();
				SqlString RewardCodeSQL = RewardCode;
				_dbadapter.UpdateCommand.Parameters["@RewardCode"].Value = RewardCodeSQL;
				SqlString FoundationSQL = Foundation;
				_dbadapter.UpdateCommand.Parameters["@Foundation"].Value = FoundationSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString ObjectSQL = Object;
				_dbadapter.UpdateCommand.Parameters["@Object"].Value = ObjectSQL;
				SqlString FormSQL = Form;
				_dbadapter.UpdateCommand.Parameters["@Form"].Value = FormSQL;
				SqlString LevelSQL = Level;
				_dbadapter.UpdateCommand.Parameters["@Level"].Value = LevelSQL;
				SqlString SourceSQL = Source;
				_dbadapter.UpdateCommand.Parameters["@Source"].Value = SourceSQL;
				SqlMoney TotalValueSQL = TotalValue;
				_dbadapter.UpdateCommand.Parameters["@TotalValue"].Value = TotalValueSQL;
				SqlInt32 StatusSQL = Status;
				_dbadapter.UpdateCommand.Parameters["@Status"].Value = StatusSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlDateTime DecideDateSQL = SqlDateTime.Null;
				if (DecideDate > DateTime.MinValue)
				{
					try
					{
						DecideDateSQL = DecideDate;
					}
					catch (Exception eDecideDate)
					{
						String DecideDateMessage = eDecideDate.Message;
						DecideDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@DecideDate"].Value = DecideDateSQL;
				SqlString PersonSQL = Person;
				_dbadapter.UpdateCommand.Parameters["@Person"].Value = PersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_REWARD_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_REWARD_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_REWARD_Disable(String RewardCode, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_REWARD_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RewardCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlString RewardCodeSQL = RewardCode;
				_dbadapter.UpdateCommand.Parameters["@RewardCode"].Value = RewardCodeSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_REWARD_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_REWARD_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_REWARD_Delete(String RewardCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_REWARD_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@RewardCode", SqlDbType.VarChar, 20));
				_dbadapter.DeleteCommand.Prepare();
				SqlString RewardCodeSQL = RewardCode;
				_dbadapter.DeleteCommand.Parameters["@RewardCode"].Value = RewardCodeSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_REWARD_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_REWARD_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_REWARD_Save(String RewardCode, String Foundation, String Reason, String Object, String Form, String Level, String Source, Decimal TotalValue, Int32 Status, DateTime Date, String DecideNumber, DateTime DecideDate, String Person)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_REWARD_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RewardCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Foundation", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Object", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Form", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Level", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Source", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@TotalValue", SqlDbType.Money));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Status", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideNumber", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DecideDate", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Person", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Prepare();
				SqlString RewardCodeSQL = RewardCode;
				_dbadapter.UpdateCommand.Parameters["@RewardCode"].Value = RewardCodeSQL;
				SqlString FoundationSQL = Foundation;
				_dbadapter.UpdateCommand.Parameters["@Foundation"].Value = FoundationSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlString ObjectSQL = Object;
				_dbadapter.UpdateCommand.Parameters["@Object"].Value = ObjectSQL;
				SqlString FormSQL = Form;
				_dbadapter.UpdateCommand.Parameters["@Form"].Value = FormSQL;
				SqlString LevelSQL = Level;
				_dbadapter.UpdateCommand.Parameters["@Level"].Value = LevelSQL;
				SqlString SourceSQL = Source;
				_dbadapter.UpdateCommand.Parameters["@Source"].Value = SourceSQL;
				SqlMoney TotalValueSQL = TotalValue;
				_dbadapter.UpdateCommand.Parameters["@TotalValue"].Value = TotalValueSQL;
				SqlInt32 StatusSQL = Status;
				_dbadapter.UpdateCommand.Parameters["@Status"].Value = StatusSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString DecideNumberSQL = DecideNumber;
				_dbadapter.UpdateCommand.Parameters["@DecideNumber"].Value = DecideNumberSQL;
				SqlDateTime DecideDateSQL = SqlDateTime.Null;
				if (DecideDate > DateTime.MinValue)
				{
					try
					{
						DecideDateSQL = DecideDate;
					}
					catch (Exception eDecideDate)
					{
						String DecideDateMessage = eDecideDate.Message;
						DecideDateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@DecideDate"].Value = DecideDateSQL;
				SqlString PersonSQL = Person;
				_dbadapter.UpdateCommand.Parameters["@Person"].Value = PersonSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_REWARD_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_REWARD_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_REWARD_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_REWARD_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_REWARD_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_REWARD_Get(String RewardCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_REWARD_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@RewardCode", SqlDbType.VarChar, 20));
				_dbadapter.SelectCommand.Prepare();
				SqlString RewardCodeSQL = RewardCode;
				_dbadapter.SelectCommand.Parameters["@RewardCode"].Value = RewardCodeSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_REWARD_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
